package cn.entity.img;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class Sword extends JPanel {
    private int x;
    private int y;
    private int flySwordX;
    private int flySwordY;
    private BufferedImage[] images;
    private BufferedImage[] images1;
    public  static  int flag;
    private int index;
    private int index1;
    private BufferedImage image;
    private BufferedImage image1;
    private int width;
    private int height;
    public Sword(int x,int y) throws IOException {
        this.flySwordX = x;
        this.flySwordY = y;
        this.x = x;
        this.y = y;
        width=80;
        height=80;
        flag = 0;
        index = 0;
        index1 = 0;
        images = new BufferedImage[4];
        images1 = new BufferedImage[4];

        for(int i = 0; i < images.length; i++) {
            images[i]= ImageIO.read(new File("img/fighter/A"+i+".png"));
        }
        for(int i = 0; i < images1.length; i++) {
            images1[i]= ImageIO.read(new File("img/fighter/B"+i+".png"));
        }
        image = images[0];
        image1 = images[0];
    }
    public void paintComponent(Graphics g){
            g.drawImage(getImage(),x+30,y-10,80,80,null);
    }
 public void paint(Graphics g){
        g.drawImage(getImage1(),flySwordX+30,flySwordY-15,80,80,null);

 }
 public void flySwordStep(){
     flySwordX+=30;
    }
    public BufferedImage getImage() {
        return image;
    }
    public BufferedImage getImage1() {
        return image1;
    }
    public void setImage1(int index){
        this.image1 = images1[index];

    }
    @Override
    public int getX() {
        return x+30;
    }
    public int getFlySwordX(){
        return flySwordX;
    }
    public int getFlySwordY(){
        return flySwordY;
    }

    public void setX(int x) {
        this.x = x;
    }

    @Override
    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y-15;
    }
    @Override
    public int getWidth() {
        return width;
    }

    @Override
    public int getHeight() {
        return height;
    }
    public int getIndex() {
        return index;
    }
    public void setIndex(int index) {
        this.index = index;
    }
    public void setIndex1(int index1) {
        this.index1 = index1;
    }
    public int getIndex1(){
       return index1;
    }
    public int getImageLength(){
        return images.length;
    }
    public int getImage1Length(){
        return images1.length;
    }
    public void setImage(int index){
        this.image = images[index];
    }

}
